package com.wc.AlgoOJ_homework.AlgoOJ_BL1.C_回文日期;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/30 9:09
 * @description http://43.138.190.70:8888/p/172?tid=65f926e1f748afd09501f854
 */
public class Main {
    static int[] mm = new int[]{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int ymd;

    public static void main(String[] args) {
        ymd = sc.nextInt();
        if (isRun(ymd / 10000)) {
            mm[2] = 29;
        } else {
            mm[2] = 28;
        }
        ymd = nextDay(ymd);
        while (!isAA(ymd)) {
            ymd = nextDay(ymd);
        }
        out.println(ymd);
        while (!isABABBABA(ymd)) {
            ymd = nextDay(ymd);
        }
        out.println(ymd);
        out.flush();
    }

    static int nextDay(int ymd) {
        int y = ymd / 10000;
        int m = ymd % 10000 / 100;
        int d = ymd % 100;

        if (d < mm[m]) {
            d++;
        } else if (m < 12) {
            m++;
            d = 1;
        } else {
            y++;
            if (isRun(y)) {
                mm[2] = 29;
            } else {
                mm[2] = 28;
            }
            d = 1;
            m = 1;
        }

        return getYMD(y, m, d);
    }

    static boolean isAA(int ymd) {
        int x = ymd;
        int cp = 0;
        while (x > 0) {
            cp = cp * 10 + x % 10;
            x /= 10;
        }
        return cp == ymd;
    }

    static boolean isABABBABA(int ymd) {
        char[] s = String.valueOf(ymd).toCharArray();
        return s[0] == s[2] && s[2] == s[5] && s[5] == s[7] && s[0] != s[1] &&
                s[1] == s[3] && s[3] == s[4] && s[4] == s[6];
    }

    static int getYMD(int y, int m, int d) {
        return y * 10000 + m * 100 + d;
    }

    static boolean isRun(int y) {
        return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
